/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package designpattern.structural_patterns;

/**
 *
 * @author anh_yeu_em_nhieu_lam
 */
public class DecoratorPattern {
    public class Computer {
        public Computer() {
        }
        public String description() {
            return "Computer ";
        }
    }
    public abstract class ComponentDecorator extends Computer {
        @Override
        public abstract String description();
    }
    public class Disk extends ComponentDecorator {
        Computer computer;
        public Disk(Computer computer) {
            this.computer = computer;
        }
        @Override
        public String description() {
            return computer.description() + " has a Disk";
        }
    }
    public class CDRoom extends ComponentDecorator {
        Computer computer;
        public CDRoom(Computer computer) {
            this.computer = computer;
        }
        @Override
        public String description() {
            return computer.description() + " has a CDRoom";
        }
    }
    public class Monitor extends ComponentDecorator {
        Computer computer;
        public Monitor(Computer computer) {
            this.computer = computer;
        }
        @Override
        public String description() {
            return computer.description() + " has a Monitor";
        }
    }
    
    public static void main(String args[]) {
        DecoratorPattern decoratorPattern = new DecoratorPattern();
        Computer computer = decoratorPattern.new Computer();
        computer = decoratorPattern.new Monitor(computer);
        computer = decoratorPattern.new Disk(computer);
        computer = decoratorPattern.new CDRoom(computer);
        computer = decoratorPattern.new CDRoom(computer);
        System.out.print(computer.description());
    }
}
/*
Computer  has a Monitor has a Disk has a CDRoom has a CDRoom
 * */